Skip to content

Conversation

@Red-Portal
Copy link
Member

@Red-Portal Red-Portal commented Oct 22, 2025

This PR does the following:

  • The interface to AdvancedVI is updated to match the new v0.6 version.
  • The way vi calls optimize is slightly changed so that algorithms that expect an unconstrained space can be used without being aware of Bijectors. In particular, the user is now expected to provide a q <: Bijectors.TransformedDistribution. vi will then unwrap the underlying unconstrained distribution, which is passed to AdvancedVI. Once the algorithm terminates, the result will be wrapped back and then returned. (See also this PR for a more detailed explanation.)
  • The main file is renamed from VariationalInference.jl to Variational.jl to match the submodule name Variational.
  • The deprecated v0.2-era interface is removed.

@Red-Portal Red-Portal requested review from mhauru and penelopeysm and removed request for penelopeysm October 22, 2025 08:33
@github-actions
Copy link
Contributor

Turing.jl documentation for PR #2699 is available at:
https://TuringLang.github.io/Turing.jl/previews/PR2699/

@codecov
Copy link

codecov bot commented Oct 22, 2025

Codecov Report

❌ Patch coverage is 0% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.51%. Comparing base (ea9bb54) to head (d83148b).

Files with missing lines Patch % Lines
src/variational/Variational.jl 0.00% 27 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (ea9bb54) and HEAD (d83148b). Click for more details.

HEAD has 7 uploads less than BASE
Flag BASE (ea9bb54) HEAD (d83148b)
24 17
Additional details and impacted files
@@              Coverage Diff              @@
##           breaking    #2699       +/-   ##
=============================================
- Coverage     86.54%   57.51%   -29.03%     
=============================================
  Files            21       20        -1     
  Lines          1412     1410        -2     
=============================================
- Hits           1222      811      -411     
- Misses          190      599      +409     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@mhauru mhauru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Red-Portal.

Since this changes the user-interface, could you please set the target branch of this PR to be breaking? We use that branch to collect breaking changes into a single, larger release. Currently breaking points at the same commit as main, so you shouldn't have to mess with git history for this.

In that same process, could you also please add an entry in HISTORY.md describing to users all interface changes (arguments, return values, behaviour) and what they can do to adapt to them. Maybe a code example of "this is how you used to call vi, this is how you do the same thing now", that sort of thing.

@Red-Portal Red-Portal changed the base branch from main to breaking October 24, 2025 02:03
Red-Portal and others added 8 commits October 24, 2025 00:00
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@Red-Portal Red-Portal requested a review from mhauru October 24, 2025 04:30
@penelopeysm
Copy link
Member

I'm actually sorry to butt in on this, but are there new features available in 0.5, or is it just an interface change?

@Red-Portal
Copy link
Member Author

@penelopeysm No new features.

@penelopeysm
Copy link
Member

Okay. The reason why I asked is because this is an interface change for Turing and that is kind of annoying for end users if they don't get any benefit. I wonder in that case if it is worth doing either:

  1. Not bumping the compat in Turing, waiting for the next release of AdvancedVI that has new features; or

  2. Mapping the existing Turing interface to the new AdvancedVI interface, so that it's not a breaking change. I don't know how possible this is.

Other than that, I second everything that @mhauru brought up here, so I won't also review the details of this.

Red-Portal and others added 5 commits October 24, 2025 22:38
Co-authored-by: Markus Hauru <markus@mhauru.org>
Co-authored-by: Markus Hauru <markus@mhauru.org>
Co-authored-by: Markus Hauru <markus@mhauru.org>
@Red-Portal
Copy link
Member Author

Hi @penelopeysm @mhauru @yebai , I've updated the code to match the new v0.6 version. Let me know if you have any comments!

Copy link
Member

@mhauru mhauru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Red-Portal, thanks for this. The code looks good, just some comments here and there on documentation, since I think it's important to get it right for such a big change.

Comment on lines +301 to +302
If the chosen variational inference algorithm operates in an unconstrained space, then the provided initial variational approximation `q` must be a `Bijectors.TransformedDistribution` of an unconstrained distribution.
For example, the initialization supplied by `q_meanfield_gaussian`,`q_fullrank_gaussian`, `q_locationscale`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just trying to understand the meaning of this: What would be choices of q that would not be valid for an unconstrained-space-requiring algorithm?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like LogNormal, Dirichlet, and of course all discrete support distributions.

using Turing
using Turing.Variational

@testset "ADVI" begin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I often find it helpful that all the tests in a file are wrapped in a single big testset. Makes the output easier to read. Did you have a particular reason to prefer otherwise here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already wrapped in runtests.jl by variational_algorithms and we're testing essentially all of the functionalities in the Variational module. So I think an additional @testset wrap is redundant at the moment.

HISTORY.md Outdated

- The default hyperparameters of `DoG`and `DoWG` have been altered.
- The deprecated `AdvancedVI@0.2`-era interface is now removed.
- `estimate_objective` now returns the value to be minimized by the optimization algorithm. For example, for ELBO maximization algorithms, `estimate_objective` will return the *negative ELBO*. This is breaking change from the previous behavior where the ELBO was returns.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think estimate_objective isn't exported by Turing. Is there some other way in which this change is visible to Turing users?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in an export sense, but the tutorial here brought it up, so I thought it would be nice to state explicitly.

Red-Portal and others added 12 commits November 27, 2025 15:27
Co-authored-by: Markus Hauru <markus@mhauru.org>
Co-authored-by: Markus Hauru <markus@mhauru.org>
Co-authored-by: Markus Hauru <markus@mhauru.org>
Co-authored-by: Markus Hauru <markus@mhauru.org>
Co-authored-by: Markus Hauru <markus@mhauru.org>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Markus Hauru <markus@mhauru.org>
@Red-Portal Red-Portal requested a review from mhauru November 27, 2025 21:03
Red-Portal and others added 5 commits November 27, 2025 16:06
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants